<?php
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport('joomla.application.component.model');

class auctionModelOrders extends JModel
{

	function getList()
	{ 
		global $mainframe;
		
		// Initialize variables
		$db		=& $this->getDBO();

		if (!empty($this->_list)) {
			return $this->_list;
		}
		
		// Get some variables from the request
		$option				= JRequest::getCmd( 'option' );
		$limit				= $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
		$limitstart			= $mainframe->getUserStateFromRequest('sessions.limitstart', 'limitstart',		0,	'int');


		// Get the total number of records
		$query = 'SELECT up.date, up.id as order_id, u.* FROM #__users_pay up INNER JOIN #__users as u ON up.user_id = u.id WHERE success = 1 AND refund = 0 ORDER BY up.id DESC';
		$db->setQuery($query);
		$this->_list = $db->loadObjectList();
		$total = count($rows);

		// Create the pagination object
		jimport('joomla.html.pagination');
		$this->_page = new JPagination($total, $limitstart, $limit);

		//If there is a db query error, throw a HTTP 500 and exit
		if ($db->getErrorNum()) {
			JError::raiseError( 500, $db->stderr() );
			return false;
		}

		return $this->_list;
	}

	function getPagination()
	{
		if (is_null($this->_list) || is_null($this->_page)) {
			$this->getList();
		}
		return $this->_page;
	}
}